#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 16:32:56 2020
@author: H
"""
from sklearn.externals import joblib
from pandas import read_csv
import pandas as pd
import numpy as np
import matplotlib.font_manager as fm
#myfont = fm.FontProperties(fname='/Users/H/Library/Fonts/NotoSerifCJKsc-Regular.otf')
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import Imputer
#from sklearn.decomposition import PCA
from sklearn.decomposition import FastICA
import matplotlib.font_manager as fm
myfont = fm.FontProperties(fname='/System/Library/Fonts/STHeiti Light.ttc')
from pyearth import Earth
from sklearn.model_selection import train_test_split
import sklearn.metrics as measure
from matplotlib import style
from scipy.stats import norm
import math
import random
import time
import matplotlib.pyplot as plt
from sklearn.metrics import mean_absolute_error as mae
import seaborn as sns
from sklearn.model_selection import cross_val_score
import dill
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,AutoMinorLocator)

#加载模型
ica = joblib.load("ica_model.m")
mars = joblib.load("mars_model.m")
icamars = joblib.load("ica-mars_model.m")


#加载数据
df = read_csv('example_input.csv')
dfc = ica.transform(df)

#计算
y_predict = icamars.predict(dfc)
y_predict1 = mars.predict(df)

#画图
plt.figure()
plt.plot(df.iloc[:,10],y_predict,'b.',label='MARS prediction',alpha=0.83,marker = 'x')
plt.plot(df.iloc[:,10],y_predict,'r*',label='ICAMARS prediction',alpha=0.83,marker = 'v')
plt.legend()
plt.xlabel('Pull-out force（kN）',fontproperties=myfont)
plt.ylabel('Pull-out displacement（mm）',fontproperties=myfont)
plt.legend()
# plt.yscale('log')
# plt.xscale('log')
plt.savefig('p_d.png',dpi=300)
plt.show()

plt.figure()
plt.plot(df.iloc[:,10],y_predict,'b.',label='MARS',alpha=0.83,marker = 'x')
plt.plot(df.iloc[:,10],y_predict,'r*',label='ICAMARS',alpha=0.83,marker = 'v')
plt.legend(prop=myfont)
plt.xlabel('抗浮力（kN）',fontproperties=myfont)
plt.ylabel('预测的位移（mm）',fontproperties=myfont)
plt.legend()
# plt.yscale('log')
# plt.xscale('log')
plt.savefig('p_dc.png',dpi=300)
plt.show()